package com.ta.gulimall.order.config.rabbitmq.listener;

import com.rabbitmq.client.Channel;
import com.ta.gulimall.order.config.rabbitmq.MqQueueConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
@Component
@Slf4j
public class BackupWithWaringQueueConsume {

//    @RabbitHandler(isDefault = true)
//    public void consume(Message message, Channel channel) throws IOException {
//        try {
//            String body = new String(message.getBody());
//            consume(body);
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        } catch (Exception e) {
//            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
//        }
//    }
//
//    private void consume(String body) {
//
//    }

    @RabbitListener(queues = MqQueueConstant.BACKUP_QUEUE_NAME)
    public void back(Message message, Channel channel) throws IOException {
        String s = new String(message.getBody());
        log.info("备份队列消费了消息:{}",s);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

//    @RabbitListener(queues = MqQueueConstant.WARING_QUEUE_NAME)
//    public void waring(Message message, Channel channel) throws IOException {
//        String s = new String(message.getBody());
//        log.error("警告消息:{}不可路由",s);
//        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//    }
}
